Skip to content

Lowering fixes found rewriting kiwi_codec's generator - #24

Merged
dannote merged 5 commits into
masterfrom
fallible-receivers
Oct 26, 2026
Merged

dannote merged 5 commits into
masterfrom
fallible-receivers

Conversation

@dannote

@dannote dannote commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Three gaps found while moving kiwi_codec's Rustler generator onto ordinary RustQ modules (open-pencil/kiwi_codec#8).

  • defrustmacro functions can name the module's types. Their specs used to be parsed without the module's type aliases, so @spec name(R.slice(variant())) :: … failed with "no Rust type". They now lower with the same aliases defrust uses, passed through one build context instead of five positional arguments.
  • A fallible method receiver propagates its error. For example, decoder.read_bool().encode(env) now lowers to decoder.read_bool()?.encode(env), as a fallible operand already did. This applies to Result and NifResult receivers calling a method Result lacks.
  • A loop over a slice reads each item by reference. for name <- names over a &[String], or over a list behind a reference, binds name as &String, so passing it where a reference is expected no longer borrows it twice. clippy rejects that double borrow as needless_borrow.

mix ci passes. With this branch and #23, Figler's mix ci passes, clippy included, apart from the package tests, which can't build a Hex package while dependencies are local paths.

The functions a defrustmacro defines parsed their specs without the
module's type aliases, so naming one of its struct types failed. The
macros now lower with the same aliases defrust does, passed with the
rest of what lowering a module's macros needs as one context.
A Result or NifResult receiving a method Result lacks, as
decoder.read_bool().encode(env), was lowered as is and failed to compile.
It now propagates with ?, as a fallible operand does.
for item <- slice binds each item as a reference, as Rust's for loop
does, so a call taking a reference no longer borrows it again.
@dannote
dannote merged commit da933cf into master Oct 26, 2026
2 checks passed
@dannote dannote mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant